import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { InputButton, ExecuteButton, SynchronizeButton, SelectButton } from '../Common/options'
import { ProjectList, IdentityLevel, winningBidder } from '../Common/Conversion'
import { DataSynchronization } from '../Common/Conversion'

import { project } from '../../../Data'
const { client_id } = project[window.location.hostname]

export const organizationLab = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    const centNameOptions = await DataSynchronization()
    let data = {
        type: '系统设置',
        pageSize: 10,
        params: { pageIndex: 1 },
        get: API_LIST()[`getOrganization`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            <SelectButton
                key="select"
                title="上传数据"
                OptionsEvent={OptionsEvent}
                type="primary"
                data={{
                    actionRef,
                    options: centNameOptions,
                    label: '上传位置',
                    url: 'posBCCenterPushPushOrganizationState',
                }}
            />,
        ],

        columns: [
            commonTableList.uuid,
            { ...commonTableList.projectUuid, valueEnum: await ProjectList(), width: 300 },
            { ...commonTableList.code, rules: true, title: '编号' },
            { ...commonTableList.tableName, title: '机构名称' },
            { ...commonTableList.fullName, rules: false, hideInSearch: true },

            {
                dataIndex: 'isLabData',
                title: '仪器试验业务',
                valueType: 'select',
                valueEnum: { 0: '无', 1: '有' },
                width: 150,
            },
            {
                dataIndex: 'isOtherLabData',
                title: '非仪器试验业务',
                valueType: 'select',
                valueEnum: { 0: '无', 1: '有' },
                width: 150,
            },
            {
                dataIndex: 'notLabDataReason',
                title: '原因',
                valueType: 'input',
                ellipsis: true,
                width: 200,
            },
            client_id !== 'bada' && {
                dataIndex: 'winningBidderUuid',
                title: '中标单位',
                valueType: 'select',
                valueEnum: await winningBidder(),
                width: 150,
            },
            { ...commonTableList.sortId, rules: true, hideInSearch: true },
            {
                dataIndex: 'identityLevel',
                title: '身份',
                valueType: 'select',
                valueEnum: await IdentityLevel(),
                width: 150,
                hideInSearch: true,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 360,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, isLabData, isOtherLabData } = record
                    return [
                        Permission.findIndex(v => v.uuid === '0c618b22-2ede-45e7-9690-dde1e0f0d721') !== -1 && (
                            <ExecuteButton
                                actionRef={actionRef}
                                key="one"
                                title="仪器试验业务"
                                url="posOrganizationLabUpdateIsLabData"
                                path={[`?uuid=${uuid}&columnName=IsLabData&columnValue=${isLabData === 0 ? '1' : '0'}`]}
                                tips="成功修改仪器试验业务状态!"
                            />
                        ),
                        Permission.findIndex(v => v.uuid === '90e6c699-c58e-4a1e-8a4f-9fe2fe2f43c1') !== -1 && (
                            <ExecuteButton
                                actionRef={actionRef}
                                key="two"
                                title="非仪器试验业务"
                                url="posOrganizationLabUpdateIsLabData"
                                path={[
                                    `?uuid=${uuid}&columnName=IsOtherLabData&columnValue=${
                                        isOtherLabData === 0 ? '1' : '0'
                                    }`,
                                ]}
                                tips="成功修改非仪器试验业务状态!"
                            />
                        ),
                        Permission.findIndex(v => v.uuid === 'a591c225-4204-4c2d-94a8-8000408c674e') !== -1 && (
                            <InputButton
                                key="add"
                                OptionsEvent={OptionsEvent}
                                title="添加原因"
                                data={{
                                    smallTitle: '添加原因',
                                    path: [],
                                    record,
                                    actionRef,
                                    label: '原因',
                                    field: 'notLabDataReason',
                                    url: 'putOrganization',
                                }}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
